package com.bjtime.designer.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.DashPathEffect
import android.graphics.Paint
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import android.widget.Toast
import com.bjtime.designer.R
import com.bjtime.designer.utils
import com.bjtime.designer.widget.BaseLabelView


class LineView : View {

    var des_line_type = 0
    var des_line_height = 1

    private var mPaint = Paint(Paint.ANTI_ALIAS_FLAG)
    init {

        mPaint.color = -0x1000000
        mPaint.style = Paint.Style.STROKE
        mPaint.strokeWidth = 3f
        mPaint.pathEffect = DashPathEffect(floatArrayOf(0f, 0f), 0f)
        setLayerType(LAYER_TYPE_SOFTWARE, null)
    }

    constructor(context: Context) : this(context, null as AttributeSet)

    constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    fun setLineStyle (type : Int) {
        Toast.makeText(context, "" + type, Toast.LENGTH_SHORT).show()
        when (type) {
            0 -> {
                des_line_type = 0
                mPaint.pathEffect = DashPathEffect(floatArrayOf(0f, 0f), 0f)
            }
            1 -> {
                des_line_type = 1
                mPaint.pathEffect = DashPathEffect(floatArrayOf(5f, 5f), 0f)
            }
        }
        invalidate()
    }

    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        super.onSizeChanged(w, h, oldw, oldh)
        mPaint.strokeWidth = utils.dp2px(context, h.toFloat()).toFloat()

    }

    fun getLineStyle(): Int {
        return des_line_type
    }

    fun getLineWidth(): Int {
        return mPaint.strokeWidth.toInt()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //val centerY = height / 2
        //canvas.drawRect(Rect (0,0,width, height), mPaint)
        canvas.drawLine(0f, 0f, width.toFloat (), 1f, mPaint)
    }



}